﻿Imports PTIC_GestionBDD
Imports OMANE.Common.Model.Interfaces

Namespace moteurTauxGaranti2

    Public Class ParamSpecifiqueModProj
        Implements OMANE.Common.Model.Interfaces.IParamSpecifiqueModProj

        Protected _valeurPerso As Double
        Protected _typeCalcul As IParamSpecifiqueModProj.typeCalcul
        Protected _sommeBase As Double
        Protected _requeteSumBase As RequeteBDD

        Public Sub New(ByVal requeteSumBase As RequeteBDD)
            _requeteSumBase = requeteSumBase
        End Sub
        Public Property valeurPerso() As Double Implements IParamSpecifiqueModProj.valeurPerso
            Get
                Return _valeurPerso
            End Get
            Set(ByVal value As Double)
                If value <> _valeurPerso Then
                    Dim e As New ParamSpecifiqueModProjEventArgs(_valeurPerso, IParamSpecifiqueModProjEventArgs.typeChangement.valeurPerso)
                    _valeurPerso = value
                    RaiseEvent hasChanged(Me, e)
                End If
            End Set
        End Property
        Public Property methodeCalcul() As IParamSpecifiqueModProj.typeCalcul Implements IParamSpecifiqueModProj.methodeCalcul
            Get
                Return _typeCalcul
            End Get
            Set(ByVal value As IParamSpecifiqueModProj.typeCalcul)
                If value <> _typeCalcul Then
                    Dim e As New ParamSpecifiqueModProjEventArgs(_typeCalcul, IParamSpecifiqueModProjEventArgs.typeChangement.methodeCalcul)
                    _typeCalcul = value
                    RaiseEvent hasChanged(Me, e)
                End If
            End Set
        End Property
        Friend ReadOnly Property sommeBase() As Double
            Get
                _requeteSumBase.Calculer_DataTable()
                Dim tbleResult As DataTable = _requeteSumBase.DataTableResultat
                Dim result As Double = 0
                If Not tbleResult Is Nothing Then
                    result = tbleResult.Rows(0)(0)
                End If
                Return result
            End Get
        End Property
        Friend Function valeurPourMoteur(ByVal valeurTraitementEntree As Double) As Double
            Dim ratio As Double = valeurTraitementEntree / sommeBase
            Dim result As Double = 0
            If methodeCalcul = IParamSpecifiqueModProj.typeCalcul.DepuisBase Then
                result = valeurTraitementEntree
            Else
                result = ratio * valeurPerso
            End If
            Return result
        End Function

        Public Event hasChanged As ParamSpecifiqueModProjEventHandler Implements IParamSpecifiqueModProj.hasChanged

    End Class


End Namespace